<template>
  <el-cascader
    :props="props"
    :options="treeList"
    separator="-"
    :value="value"
    size="mini"
    @change="getId"
  />
</template>

<script>
import { getDepartment } from '@/api/department'
import { transListToTreeData } from '@/utils/index'

export default {
  props: {
    value: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      treeList: [],
      props: {
        label: 'name',
        value: 'id'
      }
    }
  },
  created() {
    this.getDepartment()
  },
  methods: {
    async getDepartment() {
      this.treeList = transListToTreeData(await getDepartment(), 0)
      console.log(this.treeList)
    },
    getId(e) {
      if (e.length > 0) {
        this.$emit('input', e[e.length - 1])
      } else {
        this.$emit('input', null)
      }
    }
  }
}
</script>

<style>

</style>
